package com.cn.study.entity;

import com.cn.study.common.ResultCode;

import java.io.Serializable;

/**
 * @author mjy
 * @Description
 * @create 2021-06-15 13:35
 */
public class ResultVO<T>  implements Serializable {

    private static final ResultCode SUCCESS = ResultCode.SUCCESS;
    private static final ResultCode FAIL = ResultCode.FAILED;

    private Integer code;

    private String message;

    private T  data;

    public static <T> ResultVO<T> ok() {

        return result(SUCCESS,null);
    }

    public static <T> ResultVO<T> ok(T data) {
        return result(SUCCESS,data);
    }

    public static <T> ResultVO<T> ok(ResultCode resultCode) {
        return result(resultCode,null);
    }

    public static <T> ResultVO<T> ok(ResultCode resultCode, T data) {
        return result(resultCode,data);
    }

    public static <T> ResultVO<T> fail() {
        return result(FAIL,null);
    }

    public static <T> ResultVO<T> fail(ResultCode resultCode) {
        return result(resultCode,null);
    }


    public static <T> ResultVO<T> fail(T data) {
        return result(FAIL,data);
    }

    public static <T> ResultVO<T> fail(ResultCode resultCode, T data) {
        return result(resultCode,data);
    }

    private static <T>  ResultVO<T> result(ResultCode resultCode, T data) {
        ResultVO<T> resultVO = new ResultVO<>();
        resultVO.setCode(resultCode.getCode());
        resultVO.setMessage(resultCode.getMessage());
        resultVO.setData(data);
        return resultVO;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
